﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;


namespace Brunch
{
	[Serializable]
	public class ProjectConfig : ICloneable
	{
		static int globalId = 0;
		int id;

		public ProjectConfig()
		{
			id = ++globalId;
		}

		#region Properties

		[XmlAttribute]
		public string ProjectName { get; set; }

		private string rootPath;
		[XmlAttribute]
		public string RootPath
		{
			get
			{
				return rootPath;
			}
			set
			{
				if (value.EndsWith(Convert.ToString(Path.DirectorySeparatorChar)))
					rootPath = value.Substring(0, value.Length - 1);
				else
					rootPath = value;
			}
		}

		[XmlIgnore]
		public object Tag { get; set; } 

		#endregion

		public bool IsValid()
		{
			if (string.IsNullOrEmpty(RootPath))
				throw new ApplicationException("Please select root path");

			if (string.IsNullOrEmpty(ProjectName))
				throw new ApplicationException("Please fill in project name");

			return true;
		}

		public void CopyPropertiesFrom(ProjectConfig src)
		{
			ProjectName = src.ProjectName;
			RootPath = src.RootPath;
			Tag = src.Tag;
		}

		#region ICloneable Members

		public object Clone()
		{
			var clone = new ProjectConfig();

			clone.CopyPropertiesFrom(this);

			return clone;
		}

		#endregion
	}
}
